class RatingCriterion < ActiveRecord::Base
  belongs_to :review_type
  has_many :ratings
  has_many :reviews, :through=>:ratings
  
  NAME_PREFIX="01EDB0AF-D18E-46E7-A48A-7743854C64BF_"
  OVERALL_NAME="Overall"

  def prefixed_name
    NAME_PREFIX+name
  end

  def self.overall_name?(name)
    name==OVERALL_NAME
  end

  def overall?
    RatingCriterion.overall_name? name
  end

  def rating_scale_elements
    rating_scale.rating_scale_elements
  end
  
  def get_rating_scale_element(rating_value)
    rating_scale.get_rating_scale_element(rating_value)
  end
  
  def rating_scale
    RatingScale.instance
  end
  
  def avg_rating
    review_type.get_avg_rating(self)
  end
  
  def get_percent_of_ratings(rating_scale_element)
    review_type.get_percent_of_ratings(self,rating_scale_element)
  end

  def get_num_of_ratings(rating_scale_element)
    review_type.get_num_of_ratings(self,rating_scale_element)
  end

end
